package com.itheima.dao.impl;

import com.itheima.dao.UserDao;

import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.PreparedStatement;

public class UserDaoImpl implements UserDao {
    private DataSource dataSource;

    public void setDataSource(DataSource dataSource) {
        this.dataSource = dataSource;
    }

    @Override
    public void save()throws Exception {
        //1. 获取数据库连接
        Connection con = dataSource.getConnection();
        //2. sql语句
        String sql = "insert into userInfo values(id,?,?)";
        //3. 获取预编译处理对象
        PreparedStatement st = con.prepareStatement(sql);
        //4. 占位符传值
        st.setString(1,"貂蝉");
        st.setString(2,"666");
        //5. 执行预编译处理
        int i = st.executeUpdate();
        System.out.println(i);
        //6. 释放资源
        con.close();
    }
}
